package com.yuju.order.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.BufferUnderflowException;
import org.apache.tools.ant.taskdefs.ManifestTask.Mode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yuju.account.enums.AccountReturnCodeEnum;
import com.yuju.account.enums.BusinessTypeDetailEnum;
import com.yuju.account.service.IAccountService;
import com.yuju.account.service.impl.AccountServiceImpl;
import com.yuju.common.PageModel;
import com.yuju.common.Result;
import com.yuju.common.core.dao.IBaseDao;
import com.yuju.common.core.service.AbstractBaseService;
import com.yuju.enums.ReturnCodeEnum;
import com.yuju.enums.ReturnStatusEnum;
import com.yuju.enums.SeqCodeEnum;
import com.yuju.enums.StatusEnum;
import com.yuju.exception.BusinessException;
import com.yuju.group.service.ICodeGenService;
import com.yuju.hotel.enums.CustomersEnum;
import com.yuju.order.dao.IReserveDao;
import com.yuju.order.dao.entity.Reserve;
import com.yuju.order.dao.entity.ReserveRoom;
import com.yuju.order.enums.ChannelEnum;
import com.yuju.order.enums.RentTypeEnum;
import com.yuju.order.enums.ReserveReturnCodeEnum;
import com.yuju.order.enums.ReserveRoomReturnCodeEnum;
import com.yuju.order.enums.ReserveStatusEnum;
import com.yuju.order.enums.RoomOrderReturnCodeEnum;
import com.yuju.order.enums.SourceEnum;
import com.yuju.order.model.ReserveModel;
import com.yuju.order.model.ReserveRoomModel;
import com.yuju.order.model.RoomOrderModel;
import com.yuju.order.service.IReserveRoomService;
import com.yuju.order.service.IReserverService;
import com.yuju.roomStatus.model.RoomTypeStatusModel;
import com.yuju.roomStatus.service.IRoomTypeStatusService;
import com.yuju.util.Utils;
/**
 * 
 * 类名：ReserveServiceImpl  <br />
 *
 * 功能：
 *
 * @author : sunyl <br />
 * @Date : 2017年11月24日 上午9:37:41  <br />
 * @version : 1.1 <br />
 */
@Service
public class ReserveServiceImpl extends AbstractBaseService<ReserveModel,Reserve,String> implements IReserverService{
	@Autowired
	private IReserveDao reserveDao;
	@Autowired
	private IReserveRoomService reserveRoomService;
	@Autowired
	private ICodeGenService codeGenService;
	@Autowired
	private IRoomTypeStatusService roomTypeStatusService;
	@Autowired
	private IAccountService accountService;
	
	@Override
	public IBaseDao<ReserveModel, Reserve, String> getDao() {
		return reserveDao;
	}
	/*
	 * 基本保存操作
	 */
	@Override
	public int save(ReserveModel model) {
		// 保存数据
		model.setId(Utils.getUUID());
		model.setGmtCreate(new Date());
		model.setGmtModified(new Date());
		int rows = super.save(model);
		return rows;
	}
	/**
	 * 
	 * 功能：<br/>
	 * @param  model 房间
	 * @param  reserveRoomModelList 房间预订的列表
	 * 1.保存预订单
	 * 2.保存预定房间订单
	 * @author sunyl
	 * @Date 2017年12月4日 下午4:03:47 <br/>
	 */
	@Override
	public String creatReserveOrder(ReserveModel model,List<ReserveModel> reserveRoomModelList) {
		/*0 校验房态*/
		checkRoomStatus(model, reserveRoomModelList);
		/*1 保存预订单*/
		String id = Utils.getUUID();
		model.setId(id);
		String reserveNo = codeGenService.generate(model.getGroupId(), model.getHotelId(), model.getHotelCode(),SeqCodeEnum.RESERVE_CODE.getCode());
		if(reserveNo == null){
			throw new BusinessException
			(ReturnCodeEnum.ORDER_NO_GEN_FALURE.getCode(), ReturnCodeEnum.ORDER_NO_GEN_FALURE.getDesc());
		}
		model.setReserveNo(reserveNo);
		model.setGmtCreate(new Date());
		model.setGmtModified(new Date());
		model.setChannelName(ChannelEnum.getNameByValue(model.getChannel()));
		model.setReserveMoney(new BigDecimal(0));
		model.setReserveStatus(ReserveStatusEnum.YDZ.getValue());
		model.setReserveStatusName(ReserveStatusEnum.YDZ.getName());
		model.setCustomTypeName(SourceEnum.getNameByValue(model.getCustomType()));
		model.setRoomCount(reserveRoomModelList.size());
		if(super.save(model) == 0){
			throw new BusinessException
			(ReserveReturnCodeEnum.RESERVE_SAVE_FAILURE.getCode(), 
					ReserveReturnCodeEnum.RESERVE_SAVE_FAILURE.getDesc());
		}
		/*2 保存预定房间订单*/
		for(ReserveModel reserveRoomModelVar :reserveRoomModelList){
			ReserveRoomModel reserveRoomModel = new ReserveRoomModel();
			reserveRoomModel.setActualBreakfast(reserveRoomModelVar.getActualBreakfast());
			reserveRoomModel.setAddBreakfast(reserveRoomModelVar.getAddBreakfast());
			reserveRoomModel.setDefaultBreakfast(reserveRoomModelVar.getDefaultBreakfast());
			reserveRoomModel.setRoomId(reserveRoomModelVar.getRoomId());
			reserveRoomModel.setRoomTypeId(reserveRoomModelVar.getRoomTypeId());
			reserveRoomModel.setRoomTypeName(reserveRoomModelVar.getRoomTypeName());
			reserveRoomModel.setRoomCode(reserveRoomModelVar.getRoomCode());
			reserveRoomModel.setRoomPrice(reserveRoomModelVar.getRoomPrice());
			if(model.getRentType() == RentTypeEnum.APRTMENT.getValue()){
				reserveRoomModel.setMonthPrice(reserveRoomModelVar.getMonthPrice());
				reserveRoomModel.setRoomPrice(this.getDayPrice(model.getInTime(), model.getOutTime(), reserveRoomModelVar.getMonthPrice()));
			}else{
				if(reserveRoomModelVar.getRoomPrice()==null){
					throw new BusinessException(RoomOrderReturnCodeEnum.ORDER_ROOMPRICE_VALID_FAILURE.getCode(), 
							RoomOrderReturnCodeEnum.ORDER_ROOMPRICE_VALID_FAILURE.getDesc());
				}
			}
			reserveRoomModel.setRemark(reserveRoomModelVar.getRemark());
			if(reserveRoomModelVar.getRemark()!=null){
				reserveRoomModelVar.setRemark(reserveRoomModelVar.getRemark()+reserveRoomModelVar.getReasonRemark());
			}else {
				reserveRoomModelVar.setRemark(reserveRoomModelVar.getReasonRemark());
			}
			reserveRoomModel.setGroupId(model.getGroupId());
			reserveRoomModel.setHotelId(model.getHotelId());
			reserveRoomModel.setReserveId(model.getId());
			int row  = reserveRoomService.save(reserveRoomModel);
			if(row == 0){
				throw new BusinessException
				(ReserveRoomReturnCodeEnum.RESERVE_ROOM_SAVE_FAILURE.getCode(), 
						ReserveRoomReturnCodeEnum.RESERVE_ROOM_SAVE_FAILURE.getDesc());
			}
		}
		return id;
	}
	/*获取日均价*/
	private BigDecimal getDayPrice(Date checkinTime,Date checkoutTime,BigDecimal monthPrice){
		if(monthPrice == null){
			throw new BusinessException(RoomOrderReturnCodeEnum.ORDER_MONTHPRICE_VALID_FAILURE.getCode(),
					RoomOrderReturnCodeEnum.ORDER_MONTHPRICE_VALID_FAILURE.getDesc());
		}
		RoomTypeStatusModel roomTypeStatusModel = roomTypeStatusService.getApartPrice
				(checkinTime,checkoutTime,monthPrice);
		return roomTypeStatusModel.getDayPrice();
	}
	/**
	 * 校验所选房态
	 * 功能：<br/>
	 *
	 * @author sunyl
	 * @Date 2018年1月3日 下午5:22:03 <br/>
	 */
	public void checkRoomStatus(ReserveModel reserveM,List<ReserveModel> reserveRoomModelList){
		List<RoomTypeStatusModel> roomTypeStatusModelList = new ArrayList<>();
		if(reserveM.getId() != null){
			ReserveRoomModel reserveRoomModel = new ReserveRoomModel();
			reserveRoomModel.setReserveId(reserveM.getId());
			List<ReserveRoomModel> reserveRoomList = reserveRoomService.list(reserveRoomModel);
			/*1 组织数据*/
			Map<String,Integer> mapForOld = new HashMap<>();
			for(ReserveRoomModel reserveModel : reserveRoomList){
				String roomTypeId = reserveModel.getRoomTypeId();
				if(mapForOld.get(roomTypeId) == null){
					mapForOld.put(roomTypeId, 1);
				}else{
					mapForOld.put(roomTypeId, mapForOld.get(roomTypeId)+1);
				}
			}
			Map<String,Integer> mapForNew = new HashMap<>();
			for(ReserveModel reserveModel : reserveRoomModelList){
				String roomTypeId = reserveModel.getRoomTypeId();
				if(mapForNew.get(roomTypeId) == null){
					mapForNew.put(roomTypeId, 1);
				}else{
					mapForNew.put(roomTypeId, mapForNew.get(roomTypeId)+1);
				}
			}
			/*2 组织参数*/
			for(Map.Entry<String, Integer> entry: mapForNew.entrySet()){
				RoomTypeStatusModel model = new RoomTypeStatusModel();
				model.setRoomTypeId(entry.getKey());
				Integer oldValue = mapForOld.get(entry.getKey()) != null ? mapForOld.get(entry.getKey()):0;
				model.setReserveRoomCount(entry.getValue() - oldValue);
				roomTypeStatusModelList.add(model);
			}
		}else{
			/*1 组织数据*/
			Map<String,Integer> map = new HashMap<>();
			
			for(ReserveModel reserveModel : reserveRoomModelList){
				String roomTypeId = reserveModel.getRoomTypeId();
				if(map.get(roomTypeId) == null){
					map.put(roomTypeId, 1);
				}else{
					map.put(roomTypeId, map.get(roomTypeId)+1);
				}
			}
			/*2 组织参数*/
			
			for(Map.Entry<String, Integer> entry: map.entrySet()){
				RoomTypeStatusModel model = new RoomTypeStatusModel();
				model.setRoomTypeId(entry.getKey());
				model.setReserveVerifyCount(entry.getValue());
				roomTypeStatusModelList.add(model);
			}	
		}
		
		/*3 校验*/
		List<RoomTypeStatusModel> roomTypeStatusModelListR = 
				roomTypeStatusService.verifyReserveRoomType(roomTypeStatusModelList, reserveM.getHotelId(),reserveM.getInTime(),reserveM.getOutTime());
		for(RoomTypeStatusModel model:roomTypeStatusModelListR){
			if(!model.getReserveVerifyStatus()){
				throw new BusinessException(ReserveReturnCodeEnum.RESERVE_ROOM_CHECK_FAILURE.getCode(),
						ReserveReturnCodeEnum.RESERVE_ROOM_CHECK_FAILURE.getDesc());
			}
		}
	}
	/*校验 房态*/
	private void checkRoomStatusForAddAndForReserveRoomModelList(ReserveModel reserveM,List<ReserveRoomModel> reserveRoomModelList){
		List<RoomTypeStatusModel> roomTypeStatusModelList = new ArrayList<>();
		/*1 组织数据*/
		Map<String,Integer> map = new HashMap<>();
		
		for(ReserveRoomModel reserveModel : reserveRoomModelList){
			String roomTypeId = reserveModel.getRoomTypeId();
			if(map.get(roomTypeId) == null){
				map.put(roomTypeId, 1);
			}else{
				map.put(roomTypeId, map.get(roomTypeId)+1);
			}
		}
		/*2 组织参数*/
		
		for(Map.Entry<String, Integer> entry: map.entrySet()){
			RoomTypeStatusModel model = new RoomTypeStatusModel();
			model.setRoomTypeId(entry.getKey());
			model.setReserveVerifyCount(entry.getValue());
			roomTypeStatusModelList.add(model);
		}	
		/*3 校验*/
		List<RoomTypeStatusModel> roomTypeStatusModelListR = 
				roomTypeStatusService.verifyReserveRoomType(roomTypeStatusModelList, reserveM.getHotelId(),reserveM.getInTime(),reserveM.getOutTime());
		for(RoomTypeStatusModel model:roomTypeStatusModelListR){
			if(!model.getReserveVerifyStatus()){
				throw new BusinessException(ReserveReturnCodeEnum.RESERVE_ROOM_CHECK_FAILURE.getCode(),
						ReserveReturnCodeEnum.RESERVE_ROOM_CHECK_FAILURE.getDesc());
			}
		}
	}
	/**
	 * 
	 * 功能：<br/>
	 * @param  model 房间
	 * @param  reserveRoomModelList 房间预订的列表
	 * 1.修改预订单
	 * 2.删除预定房间订单
	 * 3.保存预定房间订单
	 * @author sunyl
	 * @Date 2017年12月4日 下午4:03:47 <br/>
	 */
	@Override
	public String updateReserveOrder(ReserveModel model,List<ReserveModel> reserveRoomModelList) {
		/*房态校验*/
		checkRoomStatus(model, reserveRoomModelList);
		/*1 修改预订单*/
		model.setGmtModified(new Date());
		model.setRoomCount(reserveRoomModelList.size());
		int rows = super.updateSelective(model);
		if(rows == 0){
			throw new BusinessException
			(ReserveReturnCodeEnum.RESERVE_UPDATE_FAILURE.getCode(), ReserveReturnCodeEnum.RESERVE_UPDATE_FAILURE.getDesc());
		}
		/*2 删除预定房间订单*/
		ReserveRoomModel reserveRoomModelParam = new ReserveRoomModel();
		reserveRoomModelParam.setReserveId(model.getId());
		List<ReserveRoomModel> listReserveRoomModel = reserveRoomService.list(reserveRoomModelParam);
		for(ReserveRoomModel del:listReserveRoomModel){
			reserveRoomService.del(del.getId());
		}
		/*3 保存预定房间订单*/
		for(ReserveModel reserveRoomModelVar :reserveRoomModelList){
			ReserveRoomModel reserveRoomModel = new ReserveRoomModel();
			reserveRoomModel.setActualBreakfast(reserveRoomModelVar.getActualBreakfast());
			reserveRoomModel.setAddBreakfast(reserveRoomModelVar.getAddBreakfast());
			reserveRoomModel.setDefaultBreakfast(reserveRoomModelVar.getDefaultBreakfast());
			reserveRoomModel.setRoomId(reserveRoomModelVar.getRoomId());
			reserveRoomModel.setRoomTypeId(reserveRoomModelVar.getRoomTypeId());
			reserveRoomModel.setRoomTypeName(reserveRoomModelVar.getRoomTypeName());
			reserveRoomModel.setRoomCode(reserveRoomModelVar.getRoomCode());
			reserveRoomModel.setRoomPrice(reserveRoomModelVar.getRoomPrice());
			if(model.getRentType() == RentTypeEnum.APRTMENT.getValue()){
				reserveRoomModel.setMonthPrice(reserveRoomModelVar.getMonthPrice());
				reserveRoomModel.setRoomPrice(this.getDayPrice(model.getInTime(), model.getOutTime(), reserveRoomModelVar.getMonthPrice()));
			}else{
				if(reserveRoomModelVar.getRoomPrice()==null){
					throw new BusinessException(RoomOrderReturnCodeEnum.ORDER_ROOMPRICE_VALID_FAILURE.getCode(), 
							RoomOrderReturnCodeEnum.ORDER_ROOMPRICE_VALID_FAILURE.getDesc());
				}
			}
			reserveRoomModel.setRemark(reserveRoomModel.getRemark());
			reserveRoomModel.setGroupId(model.getGroupId());
			reserveRoomModel.setHotelId(model.getHotelId());
			reserveRoomModel.setReserveId(model.getId());
			int row  = reserveRoomService.save(reserveRoomModel);
			if(row == 0){
				throw new BusinessException
				(ReserveRoomReturnCodeEnum.RESERVE_ROOM_SAVE_FAILURE.getCode(), 
						ReserveRoomReturnCodeEnum.RESERVE_ROOM_SAVE_FAILURE.getDesc());
			}
		}
		return model.getId();
	}
	/**
	 * 取消预定
	 * 功能: <br/>
	 * 
	 * 重写：sunyl <br/>
	 * 
	 * @Date ：2017年12月12日 下午3:15:07<br/>
	 *  1.跟新预订单
	 *  2.更新排房订单
	 * @param reserveId
	 * @return <br/>
	 * @see com.yuju.order.service.IReserverService#cancelReserveOrder(java.lang.String)
	 */
	@Override
	public int cancelReserveOrder(String reserveId) {
		int rows = 0;
		/* 1 跟新预订单*/
		ReserveModel reserveModel = new ReserveModel();
		reserveModel.setId(reserveId);
		reserveModel.setReserveStatus(ReserveStatusEnum.QUXIAO.getValue());
		reserveModel.setReserveStatusName(ReserveStatusEnum.QUXIAO.getName());
		rows = this.updateSelective(reserveModel);
		if(rows == 0){
			throw new BusinessException
			(ReserveReturnCodeEnum.RESERVE_UPDATE_FAILURE.getCode(), 
					ReserveReturnCodeEnum.RESERVE_UPDATE_FAILURE.getDesc());
		}
		/*2 更新排房订单*/
		ReserveRoomModel reserveRoomModel = new ReserveRoomModel();
		reserveRoomModel.setReserveId(reserveId);
		List<ReserveRoomModel> listReserveRoomModel = reserveRoomService.list(reserveRoomModel);
		for(ReserveRoomModel reserveRoomModelUpdate : listReserveRoomModel){
			reserveRoomModelUpdate.setIsDeleted(StatusEnum.TRUE.getValue());
			int row =  reserveRoomService.updateSelective(reserveRoomModelUpdate);
			rows = rows + row ;
			if(row == 0){
				throw new BusinessException
				(ReserveRoomReturnCodeEnum.RESERVE_ROOM_UPDATE_FAILURE.getCode(), 
						ReserveRoomReturnCodeEnum.RESERVE_ROOM_UPDATE_FAILURE.getDesc());
			}
		}
		return rows;
	}
	/**
	 * 恢复订单 
	 * 功能: <br/>
	 * 1.跟新预订单 
	 * 2.更新排放订单
	 * 
	 * 重写：sunyl <br/>
	 * 
	 * @Date ：2017年12月12日 下午3:15:49<br/>
	 * 
	 * @param reserveId //预定单id
	 * @return <br/>
	 * @see com.yuju.order.service.IReserverService#recoverReserveOrder(java.lang.String)
	 */
	@Override
	public int recoverReserveOrder(String reserveId) {
		/*获取房态校验参数*/
		ReserveModel model = super.findById(reserveId);
		ReserveRoomModel reserveRoomModel = new ReserveRoomModel();
		reserveRoomModel.setReserveId(reserveId);
		List<ReserveRoomModel> reserveRoomModelList = reserveRoomService.list(reserveRoomModel);
		/*校验*/
		checkRoomStatusForAddAndForReserveRoomModelList(model, reserveRoomModelList);
		
		int rows = 0;
		/*1 跟新预订单*/
		ReserveModel reserveModel = new ReserveModel();
		reserveModel.setId(reserveId);
		reserveModel.setReserveStatus(ReserveStatusEnum.YDZ.getValue());
		reserveModel.setReserveStatusName(ReserveStatusEnum.YDZ.getName());
		rows = this.updateSelective(reserveModel);
		if(rows == 0){
			throw new BusinessException
			(ReserveReturnCodeEnum.RESERVE_RECOVER_FAILURE.getCode(), 
					ReserveReturnCodeEnum.RESERVE_RECOVER_FAILURE.getDesc());
		}
		/*2 更新排放订单*/
		for(ReserveRoomModel reserveRoomModelUpdate : reserveRoomModelList){
			reserveRoomModelUpdate.setIsDeleted((byte)2);
			int row =  reserveRoomService.updateSelective(reserveRoomModelUpdate);
			rows = rows + row ;
			if(row == 0){
				throw new BusinessException
				(ReserveRoomReturnCodeEnum.RESERVE_ROOM_UPDATE_FAILURE.getCode(), 
						ReserveRoomReturnCodeEnum.RESERVE_ROOM_UPDATE_FAILURE.getDesc());
			}
		}
		return rows;
	}
	/**
	 * 修改预定金
	 * 功能: <br/>
	 * 
	 * 重写：sunyl <br/>
	 * 
	 * @Date ：2017年12月12日 下午3:16:40<br/>
	 * 
	 * @param reserveId
	 * @param reserveMoney
	 * @return <br/>
	 * @see com.yuju.order.service.IReserverService#updateReserveOrderForMoney(java.lang.String, java.math.BigDecimal)
	 */
	@Override
	public int updateReserveOrderForMoney(String reserveId, BigDecimal reserveMoney) {
		int rows = 0;
		ReserveModel reserveModel = this.findById(reserveId);
		reserveModel.setId(reserveId);
		reserveModel.setReserveMoney(reserveModel.getReserveMoney().add(reserveMoney));
		rows = this.updateSelective(reserveModel);
		return rows;
	}
	/**
	 * 通过预定id获取预定的房间
	 * 功能：<br/>
	 *
	 * @author sunyl
	 * @Date 2017年12月15日 下午7:39:02 <br/>
	 */
	@Override
	public List<ReserveRoomModel> listReserveRoomModelByReserveId(String reserveId){
		ReserveRoomModel reserveRoomModel = new ReserveRoomModel();
		reserveRoomModel.setReserveId(reserveId);
		List<ReserveRoomModel> finds = reserveRoomService.list(reserveRoomModel); 
		return finds;
	}
	/**
	 * 
	 * 功能: <br/>
	 * 自定义的预定列表
	 * 
	 * @Date ：2017年12月16日 下午1:47:53<br/>
	 * 
	 * @param model reserveModel
	 * @param currentPage
	 * @param rows
	 * @return <br/>
	 * @see com.yuju.order.service.IReserverService#listInfo(com.yuju.order.model.ReserveModel, java.lang.Integer, java.lang.Integer)
	 */
	@Override
	public PageModel listInfo(ReserveModel model, Integer currentPage, Integer rows) {
		PageModel pageModel = super.pageList(model, currentPage,rows);
		if(pageModel != null && pageModel.getRows() != null){
			actionListinfo((List<ReserveModel>) pageModel.getRows());
		}
		return pageModel;
	}
	/**
	 * 处理预定列表得信息，加工
	 * 功能: <br/>
	 * 
	 * 重写：xuehj <br/>
	 * 
	 * @Date ：2018年2月6日 下午2:01:35<br/>
	 * 
	 * @param reserveModelList <br/>
	 * @see com.yuju.order.service.IReserverService#actionListinfo(java.util.List)
	 */
	@Override
	public void actionListinfo(List<ReserveModel> reserveModelList){
		for(ReserveModel reserveModel : reserveModelList){
			ReserveRoomModel reserveRoomModel = new ReserveRoomModel();
			reserveRoomModel.setReserveId(reserveModel.getId());
			/**
			 * 设置金额
			 */
			List<ReserveRoomModel> reserveRoomModelList = reserveRoomService.list(reserveRoomModel);
			reserveModel.setReserveRoomList(reserveRoomModelList);
			/**
			 * 设置日租金和总房价 根据月租金
			 */
			StringBuffer roomStrBuffer = new StringBuffer();
			for(ReserveRoomModel item:reserveRoomModelList){
				if(item.getMonthPrice()!=null && reserveModel.getRentType() == RentTypeEnum.APRTMENT.getValue() ){
					RoomTypeStatusModel roomTypeStatusModel = roomTypeStatusService.getApartPrice
							(reserveModel.getInTime(), reserveModel.getOutTime(), item.getMonthPrice());
					item.setDayPrice(roomTypeStatusModel.getDayPrice());
					item.setTotalPrice(roomTypeStatusModel.getTotalPrice());
				}
				if(item.getRoomCode() != null){
					roomStrBuffer.append(item.getRoomCode()+"("+item.getRoomTypeName()+")"+",");
				}else{
					roomStrBuffer.append(item.getRoomTypeName()+",");
				}
				
			}
			reserveModel.setRoomStr(roomStrBuffer.toString());
			
		}
	}
	/**
	 * 通过reserveId获取预订单的详细信息包含预定的房间信息
	 * 功能: <br/>
	 * 
	 * 重写：xuehj <br/>
	 * 
	 * @Date ：2017年12月18日 下午8:49:33<br/>
	 * 
	 * @param reserveId
	 * @return <br/>
	 * @see com.yuju.order.service.IReserverService#getReserveInfoByReserveId(java.lang.String)
	 */
	@Override
	public Map<String,Object> getReserveInfoByReserveId(String reserveId) {
		ReserveModel reserveModel = super.findById(reserveId);
		if(reserveModel == null){
			throw new BusinessException(ReserveReturnCodeEnum.RESERVE_QUERY_FAILURE.getCode(),
					ReserveReturnCodeEnum.RESERVE_QUERY_FAILURE.getDesc());
		}
		ReserveRoomModel reserveRoomModel = new ReserveRoomModel();
		reserveRoomModel.setReserveId(reserveId);
		reserveRoomModel.setIsDeleted(StatusEnum.FALSE.getValue());
		List<ReserveRoomModel> reserveRoomList = reserveRoomService.list(reserveRoomModel);
		if(reserveRoomList == null){
			throw new BusinessException(ReserveRoomReturnCodeEnum.RESERVE_ROOM_QUERY_FAILURE.getCode(),
					ReserveRoomReturnCodeEnum.RESERVE_ROOM_QUERY_FAILURE.getDesc());
		}
		Map<String, Object> result = new HashMap<>(2);
		result.put("reserveModel", reserveModel);
		result.put("reserveRoomList", reserveRoomList);
		return result;
	}
	
	/**
	 * 
	 * 功能: 预抵报表<br/>
	 * 
	 * 重写：zhousc <br/>
	 * 
	 * @Date ：2017年12月20日 上午10:31:26<br/>
	 * 
	 * @param record
	 * @return <br/>
	 * @see com.yuju.order.service.IReserverService#dueToArriveIn(com.yuju.order.dao.entity.Reserve)
	 */
	@Override
	public List<ReserveModel> dueToArriveIn(ReserveModel model) {
		if(Utils.isNull(model.getInTime())){
			model.setInTime(new Date());
		}
		List<Reserve> dueToArriveIn = reserveDao.dueToArriveIn(getBeanMap(model));
		return convert(dueToArriveIn);
		
	}
	/**
	 * 微信完成支付
	 * 功能：<br/>
	 *
	 * @author sunyl
	 * @Date 2018年1月12日 下午7:03:29 <br/>
	 */
	@Override
	public int wxPayFinished(String reserveNo) {
		ReserveModel model = new ReserveModel();
		model.setReserveNo(reserveNo);
		ReserveModel find = super.find(model);
		if(find == null){
			throw new BusinessException(ReserveReturnCodeEnum.RESERVE_QUERY_FAILURE.getCode()
					, ReserveReturnCodeEnum.RESERVE_QUERY_FAILURE.getDesc());
		}
		model.setId(find.getId());
		model.setReserveMoney(find.getUnpaidMoney());
		model.setReserveStatus(ReserveStatusEnum.YDZ.getValue());
		model.setReserveStatusName(ReserveStatusEnum.YDZ.getName());
		model.setGmtModified(new Date());
		if(this.updateSelective(model) == 0){
			throw new BusinessException(ReserveReturnCodeEnum.RESERVE_UPDATE_FAILURE.getCode()
					, ReserveReturnCodeEnum.RESERVE_UPDATE_FAILURE.getDesc());
			
		}
		int i = accountService.saveReserveDepositAccount(find.getGroupId(), find.getHotelId(), find.getHotelCode(), find.getId(),
				find.getUnpaidMoney(), BusinessTypeDetailEnum.BUSINESS_TYPE_DETAIL_WX.getValue(), find.getRemark());
		if(i == 0){
			throw new BusinessException(AccountReturnCodeEnum.ACCOUNT_SAVE_FAILURE.getCode()
					, AccountReturnCodeEnum.ACCOUNT_SAVE_FAILURE.getDesc());
		}
		return 1;
	}
	/**
	 * 预定抵达报表
	 * 功能: <br/>
	 * 
	 * 重写：xuehj <br/>
	 * 
	 * @Date ：2018年1月31日 上午11:45:09<br/>
	 * 
	 * @param model
	 * @param currentPage
	 * @param rows
	 * @return <br/>
	 * @see com.yuju.order.service.IReserverService#listTable(com.yuju.order.model.ReserveModel, java.lang.Integer, java.lang.Integer)
	 */
	@Override
	public Result listTable(ReserveModel model) {
		Result result = new Result();
		List<ReserveModel> list = this.list(model);
		if(list!= null && list.size()>0){
			actionListinfo(list);
		}
		Map<Object, Object> param = new HashMap<>();
		param.put("businessTime",model.getBusinessTime());
		param.put("groupId",model.getGroupId());
		param.put("hotelId",model.getHotelId());
		List<Map<String,Object>> data = this.selectReserveCountInfo(param);
		if (Utils.isNotNull(list) && list.size()>0) {
			result.setStatus(ReturnStatusEnum.SUCCESS.getCode());
			result.setMsg(ReturnStatusEnum.SUCCESS.getDesc());
			result.setReturnCode(ReserveReturnCodeEnum.RESERVE_QUERY_SUCCESS.getCode());
			result.setReturnMsg(ReserveReturnCodeEnum.RESERVE_QUERY_SUCCESS.getDesc());
			result.setRows(list);
			result.setData(data);
		} else {
			result = new Result();
			result.setStatus(ReturnStatusEnum.FAILURE.getCode());
			result.setMsg(ReturnStatusEnum.FAILURE.getDesc());
			result.setReturnCode(ReturnCodeEnum.NO_DATA.getCode());
			result.setReturnMsg(ReturnCodeEnum.NO_DATA.getDesc());
		}
		return result;
	}
	/**
	 * 预定房间类型统计
	 * 功能: <br/>
	 * 
	 * 重写：xuehj <br/>
	 * 
	 * @Date ：2018年1月31日 下午1:50:27<br/>
	 * 
	 * @param map
	 * @return <br/>
	 * @see com.yuju.order.service.IReserverService#selectReserveCountInfo(java.util.Map)
	 */
	@Override
	public List<Map<String, Object>> selectReserveCountInfo(Map<Object, Object> map) {
		return reserveDao.selectReserveCountInfo(map);
	}
}
